package org.px.service;

import org.px.domain.Department;
import org.px.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import java.sql.SQLException;
import java.util.List;

public class DepartmentService {
    private QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());

    /**
     * 获取所有部门信息
     * @return
     * @throws SQLException
     */
    public List<Department> getAllDepartments() throws SQLException {
        String sql = "SELECT dept_id, dept_name FROM department ORDER BY dept_id";
        return qr.query(sql, new BeanListHandler<>(Department.class));
    }
}